package cn.sc.summer.calculate.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.sc.summer.calculate.form.GetLogPageForm;
import cn.sc.summer.calculate.mapper.SysLogMapper;
import cn.sc.summer.calculate.service.SysLogService;
import cn.sc.summer.calculate.vo.SysLogVO;
import cn.sc.summer.constant.log.SysLog;
import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.mybatis.annotation.dynamicdatasource.DataSource;
import cn.sc.summer.mybatis.enums.DataSourceEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 类名：API访问日志信息操作业务层
 *
 * @author a-xin
 * @date 2024/2/7 16:43
 */
@Slf4j
@Service
public class SysLogServiceImpl implements SysLogService {

    @Resource
    private SysLogMapper sysLogMapper;

    /**
     * 分页获取API访问日志
     *
     * @param form 分页请求表单
     * @return api日志
     */
    @Override
    @DataSource(DataSourceEnum.POST_GRE_SQL)
    public PageResult<SysLogVO> getSysLog(GetLogPageForm form) {
        return sysLogMapper.selectPage(form, new LambdaQueryWrapper<SysLog>()
                        .eq(StrUtil.isNotBlank(form.getServiceName()), SysLog::getApiServiceName, form.getServiceName())
                        .eq(StrUtil.isNotBlank(form.getReqType()), SysLog::getReqType, form.getReqType())
                        .eq(StrUtil.isNotBlank(form.getReqIp()), SysLog::getReqIp, form.getReqType()),
                SysLogVO.class);
    }
}
